﻿dynamic class com.crystalcentral.model.DiyTextItem extends com.crystalcentral.model.DiyItem
{
	public static var DEFAULT_TEXT = "New Text Layer" + newline + "Double Click to Edit";
	private var _fontName:String;
	private var _fontSize:Number;
	private var _color:Number;
	private var _bold:Boolean;
	private var _italic:Boolean;
	private var _underline:Boolean;
	private var _align:String;
	private var _text:String;
	private var _letterSpacing:Number;
	private var _leading:Number;
	private var _wordWrap:Boolean;

	function DiyTextItem()
	{
		if (arguments.length == 0)
		{
			super();
			this._fontName = "Humanist";
			this._fontSize = 18;
			this._color = 0xCCCCCC;
			this._bold = false;
			this._italic = false;
			this._underline = false;
			this._align = "left";
			this._text = DEFAULT_TEXT;
			this._letterSpacing = 0;
			this._leading = 0;
			this._wordWrap = false;
		}
		else
		{
			var node:XMLNode = arguments[0];
			super(node);
			this._text = String(node.firstChild.nodeValue);
			this._fontName = node.attributes.font;
			this._fontSize = Number(node.attributes.size);
			this._color = Number("0x" + node.attributes.color);
			this._bold = Boolean(node.attributes.bold == "true");
			this._italic = Boolean(node.attributes.italic == "true");
			this._underline = Boolean(node.attributes.underline == "true");
			this._align = node.attributes.align;
			this._letterSpacing = node.attributes.letterSpacing == undefined ? 0 : Number(node.attributes.letterSpacing);
			this._leading = node.attributes.leading == undefined ? 0 : Number(node.attributes.leading);
			this._wordWrap = Boolean(node.attributes.wordWrap == "true");
		}
	}

	public function get fontName()
	{
		return this._fontName;
	}
	public function set fontName(val:String)
	{
		this._fontName = val;
	}

	public function get fontSize()
	{
		return this._fontSize;
	}
	public function set fontSize(val:Number)
	{
		this._fontSize = val;
	}

	public function get color()
	{
		return this._color;
	}
	public function set color(val:Number)
	{
		this._color = val;
	}

	public function get bold()
	{
		return this._bold;
	}
	public function set bold(val:Boolean)
	{
		this._bold = val;
	}

	public function get italic()
	{
		return this._italic;
	}
	public function set italic(val:Boolean)
	{
		this._italic = val;
	}

	public function get underline()
	{
		return this._underline;
	}
	public function set underline(val:Boolean)
	{
		this._underline = val;
	}

	public function get align()
	{
		return this._align;
	}
	public function set align(val:String)
	{
		this._align = val;
	}

	public function get text()
	{
		return this._text;
	}
	public function set text(val:String)
	{
		this._text = val;
	}

	public function get letterSpacing()
	{
		return this._letterSpacing;
	}
	public function set letterSpacing(val:Number)
	{
		this._letterSpacing = val;
	}

	public function get leading()
	{
		return this._leading;
	}
	public function set leading(val:Number)
	{
		this._leading = val;
	}

	public function get wordWrap()
	{
		return this._wordWrap;
	}
	public function set wordWrap(val:Boolean)
	{
		this._wordWrap = val;
	}

	public function toString():String
	{
		return "[DiyTextItem: " + this._text + "," + this._fontName + "," + this._underline + "]";
	}
	
	public function clone() {
		var obj = new DiyTextItem();
		obj._x=this._x;
		obj._y=this._y;
		obj._width=this._width;
		obj._height=this._height;
		obj._xscale=this._xscale;
		obj._yscale=this._yscale;
		obj._rotation=this._rotation;
		obj._fontName=this._fontName;
		obj._fontSize=this._fontSize;
		obj._color=this._color;
		obj._bold=this._bold;
		obj._italic=this._italic;
		obj._underline=this._underline;
		obj._align=this._align;
		obj._text=this._text;
		obj._letterSpacing=this._letterSpacing;
		obj._leading=this._leading;
		obj._wordWrap=this._wordWrap;
		
		return obj;
	}
}